/*
 * Decompiled with CFR 0.150.
 * 
 * Could not load the following classes:
 *  cn.hutool.core.util.ObjectUtil
 *  com.alibaba.fastjson.JSON
 *  de.felixroske.jfxsupport.FXMLController
 *  javafx.beans.value.ChangeListener
 *  javafx.beans.value.ObservableValue
 *  javafx.collections.FXCollections
 *  javafx.collections.ObservableList
 *  javafx.event.EventHandler
 *  javafx.fxml.FXML
 *  javafx.fxml.Initializable
 *  javafx.scene.Node
 *  javafx.scene.control.Alert
 *  javafx.scene.control.Alert$AlertType
 *  javafx.scene.control.ComboBox
 *  javafx.scene.control.TableCell
 *  javafx.scene.control.TableColumn
 *  javafx.scene.control.TableView
 *  javafx.scene.control.TextField
 *  javafx.scene.control.cell.PropertyValueFactory
 *  javafx.scene.input.KeyCode
 *  javafx.scene.input.KeyEvent
 *  javafx.scene.layout.AnchorPane
 *  javafx.stage.Modality
 *  javafx.stage.Stage
 *  javafx.util.Callback
 *  javafx.util.StringConverter
 *  org.slf4j.Logger
 *  org.slf4j.LoggerFactory
 *  org.springframework.beans.factory.annotation.Autowired
 */
package com.gys.controller.clearBox;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.gys.GysApplication;
import com.gys.common.business.AddClearBoxUtil;
import com.gys.common.business.ClearBoxUtil;
import com.gys.common.data.HttpJson;
import com.gys.common.data.KeyValue;
import com.gys.common.util.CommonUtil;
import com.gys.common.util.SpringUtil;
import com.gys.controller.BaseController;
import com.gys.controller.clearBox.ClearBoxController;
import com.gys.controller.clearBox.ClearProductQueryController;
import com.gys.controller.dataManger.ControllerManger;
import com.gys.data.clearBox.ClearBoxDetailOutData;
import com.gys.data.clearBox.GetClearQueryProductOutData;
import com.gys.view.clearBox.AddClearBoxView;
import com.gys.view.clearBox.ClearProductQueryView;
import de.felixroske.jfxsupport.FXMLController;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.ResourceBundle;
import java.util.Timer;
import java.util.TimerTask;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.control.Alert;
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.StringConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

@FXMLController
public class AddClearBoxController
extends BaseController
implements Initializable {
    private static final Logger log = LoggerFactory.getLogger(AddClearBoxController.class);
    @FXML
    private TableView<ClearBoxDetailOutData> tableView;
    @FXML
    private TableColumn<ClearBoxDetailOutData, String> gscdBatchNo;
    @FXML
    private TableColumn<ClearBoxDetailOutData, String> normalPrice;
    @FXML
    private TableColumn<ClearBoxDetailOutData, String> gscdProId;
    @FXML
    private TableColumn<ClearBoxDetailOutData, String> gscdQty;
    @FXML
    private TableColumn<ClearBoxDetailOutData, String> gscdBatch;
    @FXML
    private TableColumn<ClearBoxDetailOutData, String> indexDetail;
    @FXML
    private TableColumn<ClearBoxDetailOutData, String> gscdProName;
    @FXML
    private ComboBox<KeyValue> emp;
    @FXML
    private TextField proParam;
    @FXML
    private AnchorPane pane;
    @Autowired
    private ClearBoxController clearBoxController;
    @Autowired
    private ClearProductQueryController clearProductQueryController;
    private ObservableList<ClearBoxDetailOutData> observableTableList = FXCollections.observableArrayList(new ArrayList());
    private List<GetClearQueryProductOutData> queryProductOutData = null;

    public void initialize(URL location, ResourceBundle resources) {
        ControllerManger.controllerMap.put(this.getClass().getSimpleName(), this);
        this.emp.setItems(this.clearBoxController.gsegNameOptions);
        this.comboxInit(this.emp);
        this.band();
        this.init();
    }

    @Override
    public void init() {
        if (ObjectUtil.isEmpty(this.pane)) {
            return;
        }
        this.emp.setValue(new KeyValue());
        this.observableTableList.clear();
        this.proParam.clear();
        this.queryProductOutData = null;
        new Timer().schedule(new TimerTask(){

            @Override
            public void run() {
                AddClearBoxView view = SpringUtil.getBean(AddClearBoxView.class);
                Stage stage = (Stage)view.getView().getScene().getWindow();
                stage.getScene().setOnKeyReleased((EventHandler)new EventHandler<KeyEvent>(){

                    public void handle(KeyEvent e) {
                        if (e.getCode() == KeyCode.ENTER) {
                            AddClearBoxController.this.queryPro();
                        }
                        e.consume();
                    }
                });
            }
        }, 500L);
    }

    public void comboxInit(ComboBox box) {
        box.converterProperty().set(new StringConverter<KeyValue>(){

            public String toString(KeyValue object) {
                return object.getName();
            }

            public KeyValue fromString(String string) {
                return null;
            }
        });
    }

    private void queryPro() {
        String inputText = this.proParam.getText().trim();
        if (ObjectUtil.isEmpty(inputText) || inputText.length() > 20) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8f93\u5165\u4e0d\u80fd\u4e3a\u7a7a\u4e14\u957f\u5ea6\u5c0f\u4e8e\u7b49\u4e8e20");
            alert.showAndWait();
            return;
        }
        HashMap<String, Object> param = new HashMap<String, Object>();
        param.put("nameOrCode", inputText);
        param.put("storageArea", "3");
        HttpJson httpJson = AddClearBoxUtil.queryProduct(param);
        if (!httpJson.isSuccess()) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
            return;
        }
        this.queryProductOutData = JSON.parseArray((String)httpJson.getMsg(), GetClearQueryProductOutData.class);
        if (this.queryProductOutData.size() == 0) {
            Alert alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u6ca1\u6709\u67e5\u5230\u6570\u636e");
            alert.showAndWait();
            return;
        }
        this.clearProductQueryController.init();
        GysApplication.showView(ClearProductQueryView.class, (Modality)Modality.APPLICATION_MODAL);
    }

    @FXML
    private void sureAction() {
        Alert alert;
        HashMap<String, Object> param = new HashMap<String, Object>();
        String empId = ((KeyValue)this.emp.getValue()).getValue();
        if (ObjectUtil.isEmpty(empId)) {
            Alert alert2 = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u9009\u62e9\u6e05\u6597\u4eba\u5458");
            alert2.showAndWait();
            return;
        }
        if (this.tableView.getItems().size() == 0) {
            Alert alert3 = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u6dfb\u52a0\u5546\u54c1");
            alert3.showAndWait();
            return;
        }
        for (int i = 0; i < this.tableView.getItems().size(); ++i) {
            String gscdQty = ((ClearBoxDetailOutData)this.tableView.getItems().get(i)).getGscdQty();
            String qtySour = ((ClearBoxDetailOutData)this.tableView.getItems().get(i)).getQtySour();
            if (ObjectUtil.isEmpty(gscdQty)) {
                Alert alert4 = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u6e05\u6597\u6570\u91cf\u8bf7\u586b\u5199\u5b8c\u6574");
                alert4.showAndWait();
                return;
            }
            if (Integer.valueOf(gscdQty) <= Integer.valueOf(qtySour)) continue;
            Alert alert5 = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u6e05\u6597\u6570\u91cf\u4e0d\u80fd\u5927\u4e8e\u6279\u53f7\u5e93\u5b58\u6570\u91cf\uff1a" + qtySour);
            alert5.showAndWait();
            return;
        }
        param.put("emp", empId);
        param.put("clearBoxDetailOutDataList", this.tableView.getItems());
        HttpJson httpJson = ClearBoxUtil.addClearBox(param);
        if (httpJson.isSuccess()) {
            alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u4fdd\u5b58\u6210\u529f");
            alert.showAndWait();
            this.cancelAction();
            this.clearBoxController.initTableViewTwo();
        } else {
            alert = this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", httpJson.getMsg());
            alert.showAndWait();
        }
    }

    public void reflsh(ClearBoxDetailOutData clearBoxDetailOutData) {
        ObservableList items = this.tableView.getItems();
        items.add(clearBoxDetailOutData);
        this.observableTableList = FXCollections.observableArrayList((Collection)items);
        this.tableView.setItems(this.observableTableList);
        this.gscdQtyToTextField();
    }

    public void gscdQtyToTextField() {
        this.gscdQty.setCellFactory(tc -> {
            final TextField textField = new TextField();
            textField.setMinHeight(30.0);
            textField.setPrefWidth(90.0);
            TableCell<ClearBoxDetailOutData, String> cell = new TableCell<ClearBoxDetailOutData, String>(){

                protected void updateItem(String chuzhi, boolean empty) {
                    super.updateItem(chuzhi, empty);
                    if (empty) {
                        this.setGraphic(null);
                    } else {
                        textField.setText(chuzhi);
                        this.setGraphic((Node)textField);
                    }
                }
            };
            textField.textProperty().addListener((ChangeListener)new ChangeListener<String>(){
                final TableCell val_cell;
                {
                    this.val_cell = cell;
                }

                public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
                    int rank = this.val_cell.getIndex();
                    if (ObjectUtil.isNotEmpty(newValue) && !CommonUtil.positiveInteger(newValue)) {
                        Alert alert = AddClearBoxController.this.createAlert(Alert.AlertType.INFORMATION, "\u63d0\u793a\u4fe1\u606f", "\u8bf7\u8f93\u5165\u6b63\u6574\u6570");
                        alert.showAndWait();
                        return;
                    }
                    ((ClearBoxDetailOutData)AddClearBoxController.this.observableTableList.get(rank)).setGscdQty(newValue);
                }
            });
            return cell;
        });
    }

    private void band() {
        this.gscdBatchNo.setCellValueFactory((Callback)new PropertyValueFactory(this.gscdBatchNo.getId()));
        this.normalPrice.setCellValueFactory((Callback)new PropertyValueFactory(this.normalPrice.getId()));
        this.gscdProId.setCellValueFactory((Callback)new PropertyValueFactory(this.gscdProId.getId()));
        this.gscdQty.setCellValueFactory((Callback)new PropertyValueFactory(this.gscdQty.getId()));
        this.gscdBatch.setCellValueFactory((Callback)new PropertyValueFactory(this.gscdBatch.getId()));
        this.indexDetail.setCellValueFactory((Callback)new PropertyValueFactory(this.indexDetail.getId()));
        this.gscdProName.setCellValueFactory((Callback)new PropertyValueFactory(this.gscdProName.getId()));
    }

    @FXML
    private void cancelAction() {
        this.pane.getScene().getWindow().hide();
    }

    public TableView<ClearBoxDetailOutData> getTableView() {
        return this.tableView;
    }

    public TableColumn<ClearBoxDetailOutData, String> getGscdBatchNo() {
        return this.gscdBatchNo;
    }

    public TableColumn<ClearBoxDetailOutData, String> getNormalPrice() {
        return this.normalPrice;
    }

    public TableColumn<ClearBoxDetailOutData, String> getGscdProId() {
        return this.gscdProId;
    }

    public TableColumn<ClearBoxDetailOutData, String> getGscdQty() {
        return this.gscdQty;
    }

    public TableColumn<ClearBoxDetailOutData, String> getGscdBatch() {
        return this.gscdBatch;
    }

    public TableColumn<ClearBoxDetailOutData, String> getIndexDetail() {
        return this.indexDetail;
    }

    public TableColumn<ClearBoxDetailOutData, String> getGscdProName() {
        return this.gscdProName;
    }

    public ComboBox<KeyValue> getEmp() {
        return this.emp;
    }

    public TextField getProParam() {
        return this.proParam;
    }

    public AnchorPane getPane() {
        return this.pane;
    }

    public ClearBoxController getClearBoxController() {
        return this.clearBoxController;
    }

    public ClearProductQueryController getClearProductQueryController() {
        return this.clearProductQueryController;
    }

    public ObservableList<ClearBoxDetailOutData> getObservableTableList() {
        return this.observableTableList;
    }

    public List<GetClearQueryProductOutData> getQueryProductOutData() {
        return this.queryProductOutData;
    }

    public void setTableView(TableView<ClearBoxDetailOutData> tableView) {
        this.tableView = tableView;
    }

    public void setGscdBatchNo(TableColumn<ClearBoxDetailOutData, String> gscdBatchNo) {
        this.gscdBatchNo = gscdBatchNo;
    }

    public void setNormalPrice(TableColumn<ClearBoxDetailOutData, String> normalPrice) {
        this.normalPrice = normalPrice;
    }

    public void setGscdProId(TableColumn<ClearBoxDetailOutData, String> gscdProId) {
        this.gscdProId = gscdProId;
    }

    public void setGscdQty(TableColumn<ClearBoxDetailOutData, String> gscdQty) {
        this.gscdQty = gscdQty;
    }

    public void setGscdBatch(TableColumn<ClearBoxDetailOutData, String> gscdBatch) {
        this.gscdBatch = gscdBatch;
    }

    public void setIndexDetail(TableColumn<ClearBoxDetailOutData, String> indexDetail) {
        this.indexDetail = indexDetail;
    }

    public void setGscdProName(TableColumn<ClearBoxDetailOutData, String> gscdProName) {
        this.gscdProName = gscdProName;
    }

    public void setEmp(ComboBox<KeyValue> emp) {
        this.emp = emp;
    }

    public void setProParam(TextField proParam) {
        this.proParam = proParam;
    }

    public void setPane(AnchorPane pane) {
        this.pane = pane;
    }

    public void setClearBoxController(ClearBoxController clearBoxController) {
        this.clearBoxController = clearBoxController;
    }

    public void setClearProductQueryController(ClearProductQueryController clearProductQueryController) {
        this.clearProductQueryController = clearProductQueryController;
    }

    public void setObservableTableList(ObservableList<ClearBoxDetailOutData> observableTableList) {
        this.observableTableList = observableTableList;
    }

    public void setQueryProductOutData(List<GetClearQueryProductOutData> queryProductOutData) {
        this.queryProductOutData = queryProductOutData;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        }
        if (!(o instanceof AddClearBoxController)) {
            return false;
        }
        AddClearBoxController other = (AddClearBoxController)o;
        if (!other.canEqual(this)) {
            return false;
        }
        TableView<ClearBoxDetailOutData> this$tableView = this.getTableView();
        TableView<ClearBoxDetailOutData> other$tableView = other.getTableView();
        if (this$tableView == null ? other$tableView != null : !this$tableView.equals(other$tableView)) {
            return false;
        }
        TableColumn<ClearBoxDetailOutData, String> this$gscdBatchNo = this.getGscdBatchNo();
        TableColumn<ClearBoxDetailOutData, String> other$gscdBatchNo = other.getGscdBatchNo();
        if (this$gscdBatchNo == null ? other$gscdBatchNo != null : !this$gscdBatchNo.equals(other$gscdBatchNo)) {
            return false;
        }
        TableColumn<ClearBoxDetailOutData, String> this$normalPrice = this.getNormalPrice();
        TableColumn<ClearBoxDetailOutData, String> other$normalPrice = other.getNormalPrice();
        if (this$normalPrice == null ? other$normalPrice != null : !this$normalPrice.equals(other$normalPrice)) {
            return false;
        }
        TableColumn<ClearBoxDetailOutData, String> this$gscdProId = this.getGscdProId();
        TableColumn<ClearBoxDetailOutData, String> other$gscdProId = other.getGscdProId();
        if (this$gscdProId == null ? other$gscdProId != null : !this$gscdProId.equals(other$gscdProId)) {
            return false;
        }
        TableColumn<ClearBoxDetailOutData, String> this$gscdQty = this.getGscdQty();
        TableColumn<ClearBoxDetailOutData, String> other$gscdQty = other.getGscdQty();
        if (this$gscdQty == null ? other$gscdQty != null : !this$gscdQty.equals(other$gscdQty)) {
            return false;
        }
        TableColumn<ClearBoxDetailOutData, String> this$gscdBatch = this.getGscdBatch();
        TableColumn<ClearBoxDetailOutData, String> other$gscdBatch = other.getGscdBatch();
        if (this$gscdBatch == null ? other$gscdBatch != null : !this$gscdBatch.equals(other$gscdBatch)) {
            return false;
        }
        TableColumn<ClearBoxDetailOutData, String> this$indexDetail = this.getIndexDetail();
        TableColumn<ClearBoxDetailOutData, String> other$indexDetail = other.getIndexDetail();
        if (this$indexDetail == null ? other$indexDetail != null : !this$indexDetail.equals(other$indexDetail)) {
            return false;
        }
        TableColumn<ClearBoxDetailOutData, String> this$gscdProName = this.getGscdProName();
        TableColumn<ClearBoxDetailOutData, String> other$gscdProName = other.getGscdProName();
        if (this$gscdProName == null ? other$gscdProName != null : !this$gscdProName.equals(other$gscdProName)) {
            return false;
        }
        ComboBox<KeyValue> this$emp = this.getEmp();
        ComboBox<KeyValue> other$emp = other.getEmp();
        if (this$emp == null ? other$emp != null : !this$emp.equals(other$emp)) {
            return false;
        }
        TextField this$proParam = this.getProParam();
        TextField other$proParam = other.getProParam();
        if (this$proParam == null ? other$proParam != null : !this$proParam.equals(other$proParam)) {
            return false;
        }
        AnchorPane this$pane = this.getPane();
        AnchorPane other$pane = other.getPane();
        if (this$pane == null ? other$pane != null : !this$pane.equals(other$pane)) {
            return false;
        }
        ClearBoxController this$clearBoxController = this.getClearBoxController();
        ClearBoxController other$clearBoxController = other.getClearBoxController();
        if (this$clearBoxController == null ? other$clearBoxController != null : !this$clearBoxController.equals(other$clearBoxController)) {
            return false;
        }
        ClearProductQueryController this$clearProductQueryController = this.getClearProductQueryController();
        ClearProductQueryController other$clearProductQueryController = other.getClearProductQueryController();
        if (this$clearProductQueryController == null ? other$clearProductQueryController != null : !(this$clearProductQueryController).equals(other$clearProductQueryController)) {
            return false;
        }
        ObservableList<ClearBoxDetailOutData> this$observableTableList = this.getObservableTableList();
        ObservableList<ClearBoxDetailOutData> other$observableTableList = other.getObservableTableList();
        if (this$observableTableList == null ? other$observableTableList != null : !this$observableTableList.equals(other$observableTableList)) {
            return false;
        }
        List<GetClearQueryProductOutData> this$queryProductOutData = this.getQueryProductOutData();
        List<GetClearQueryProductOutData> other$queryProductOutData = other.getQueryProductOutData();
        return !(this$queryProductOutData == null ? other$queryProductOutData != null : !(this$queryProductOutData).equals(other$queryProductOutData));
    }

    protected boolean canEqual(Object other) {
        return other instanceof AddClearBoxController;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        TableView<ClearBoxDetailOutData> $tableView = this.getTableView();
        result = result * 59 + ($tableView == null ? 43 : $tableView.hashCode());
        TableColumn<ClearBoxDetailOutData, String> $gscdBatchNo = this.getGscdBatchNo();
        result = result * 59 + ($gscdBatchNo == null ? 43 : $gscdBatchNo.hashCode());
        TableColumn<ClearBoxDetailOutData, String> $normalPrice = this.getNormalPrice();
        result = result * 59 + ($normalPrice == null ? 43 : $normalPrice.hashCode());
        TableColumn<ClearBoxDetailOutData, String> $gscdProId = this.getGscdProId();
        result = result * 59 + ($gscdProId == null ? 43 : $gscdProId.hashCode());
        TableColumn<ClearBoxDetailOutData, String> $gscdQty = this.getGscdQty();
        result = result * 59 + ($gscdQty == null ? 43 : $gscdQty.hashCode());
        TableColumn<ClearBoxDetailOutData, String> $gscdBatch = this.getGscdBatch();
        result = result * 59 + ($gscdBatch == null ? 43 : $gscdBatch.hashCode());
        TableColumn<ClearBoxDetailOutData, String> $indexDetail = this.getIndexDetail();
        result = result * 59 + ($indexDetail == null ? 43 : $indexDetail.hashCode());
        TableColumn<ClearBoxDetailOutData, String> $gscdProName = this.getGscdProName();
        result = result * 59 + ($gscdProName == null ? 43 : $gscdProName.hashCode());
        ComboBox<KeyValue> $emp = this.getEmp();
        result = result * 59 + ($emp == null ? 43 : $emp.hashCode());
        TextField $proParam = this.getProParam();
        result = result * 59 + ($proParam == null ? 43 : $proParam.hashCode());
        AnchorPane $pane = this.getPane();
        result = result * 59 + ($pane == null ? 43 : $pane.hashCode());
        ClearBoxController $clearBoxController = this.getClearBoxController();
        result = result * 59 + ($clearBoxController == null ? 43 : $clearBoxController.hashCode());
        ClearProductQueryController $clearProductQueryController = this.getClearProductQueryController();
        result = result * 59 + ($clearProductQueryController == null ? 43 : ($clearProductQueryController).hashCode());
        ObservableList<ClearBoxDetailOutData> $observableTableList = this.getObservableTableList();
        result = result * 59 + ($observableTableList == null ? 43 : $observableTableList.hashCode());
        List<GetClearQueryProductOutData> $queryProductOutData = this.getQueryProductOutData();
        result = result * 59 + ($queryProductOutData == null ? 43 : ($queryProductOutData).hashCode());
        return result;
    }

    public String toString() {
        return "AddClearBoxController(tableView=" + this.getTableView() + ", gscdBatchNo=" + this.getGscdBatchNo() + ", normalPrice=" + this.getNormalPrice() + ", gscdProId=" + this.getGscdProId() + ", gscdQty=" + this.getGscdQty() + ", gscdBatch=" + this.getGscdBatch() + ", indexDetail=" + this.getIndexDetail() + ", gscdProName=" + this.getGscdProName() + ", emp=" + this.getEmp() + ", proParam=" + this.getProParam() + ", pane=" + this.getPane() + ", clearBoxController=" + this.getClearBoxController() + ", clearProductQueryController=" + this.getClearProductQueryController() + ", observableTableList=" + this.getObservableTableList() + ", queryProductOutData=" + this.getQueryProductOutData() + ")";
    }
}

